package com.future.dao;

import java.sql.Connection;
import java.util.List;

import com.future.model.po.ServicesAnswerTotleModel;
import com.future.model.po.UserModel;

public class ServicesAnswerTotleDAO extends BaseDAO<ServicesAnswerTotleModel> {

	public ServicesAnswerTotleDAO() {

	}

	public ServicesAnswerTotleDAO(Connection conn) {
		super(conn);
	}

	public boolean save(ServicesAnswerTotleModel model) {
		String sql = "insert into services_answer_totle (userid , servicesid , town , community) values (?,?,?,?)";
		return this.update(sql, model.getUserid(), model.getServicesid(), model.getTown(), model.getCommunity());
	}
	public boolean update(ServicesAnswerTotleModel model) {
		String sql = "update services_answer_totle set town=?, community=? where id=?";
		return this.update(sql, model.getTown(), model.getCommunity(), model.getId());
	}

	public List<ServicesAnswerTotleModel> findByUserId(Integer userId) {
		ServicesAnswerTotleModel model = new ServicesAnswerTotleModel();
		model.setUserid(userId);
		return this.findByUserId(model);
	}

	public List<ServicesAnswerTotleModel> findByUserId(ServicesAnswerTotleModel model) {
		String sql = "select * from services_answer_totle where userid = ? ";
		return this.searchAsBeanList(sql, ServicesAnswerTotleModel.class, model.getUserid());
	}
	public List<ServicesAnswerTotleModel> findByUserId(UserModel model) {
		String sql = "select sa.id,s.services,sa.userid,sa.servicesid,sa.town,sa.community from services s  LEFT JOIN services_answer_totle  sa on s.id = sa.servicesid where userid=? ";
		return this.searchAsBeanList(sql, ServicesAnswerTotleModel.class, model.getId());
	}

	public boolean deleteByUserId(Integer userId) {
		ServicesAnswerTotleModel model = new ServicesAnswerTotleModel();
		model.setUserid(userId);
		return this.deleteByUserId(model);
	}

	public boolean deleteByUserId(ServicesAnswerTotleModel model) {
		String sql = "delete from services_answer_totle where userid = ? ";
		return this.update(sql, model.getUserid());
	}
}
